/*
 * @Description: index.js
 * @Author: zhangchenna
 * @Date: 2019-02-25 17:06:37
 * @LastEditTime: 2019-03-07 16:25:16
 */
import '../../style/home/index.scss';
import Layer from '../../components/layer/layer';
import * as hljs from 'highlight.js/lib/highlight';
import * as java from 'highlight.js/lib/languages/java';

hljs.registerLanguage('java', java);
document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('pre code').forEach(block => {
        hljs.highlightBlock(block);
    });
});

let nav = document.querySelectorAll('.header-nav-list .header-nav-item');

nav[0].classList.remove('header-nav-item-active');
nav[5].classList.add('header-nav-item-active');

function navBar() {
    nav.forEach(item => {
        if (item.className.includes('header-nav-item-active')) {
            item.classList.remove('header-nav-item-active');
        }
    });
    switch (this.innerText) {
        case '代理上架':
            window.location.href = '../agency/index.html';
            break;
        case '使用帮助':
            window.location.href = '../help/index.html';
            break;
        default:
            window.location.href = '../index/index.html';
            break;
    }
    this.classList.add('header-nav-item-active');
}

nav.forEach(item => {
    item.addEventListener('click', navBar, false);
});

let list = document.querySelectorAll('.help-left-list li'),
    rightList = document.querySelectorAll('.help-right-item');

function clear() {
    list.forEach(item => {
        if (item.className.includes('help-left-item-active')) {
            item.classList.remove('help-left-item-active');
        }
    });
    rightList.forEach(item => {
        item.classList.add('mit-hide');
    });
}

for (let i = 0; i < list.length; i++) {
    list[i].addEventListener(
        'click',
        function() {
            clear();
            this.classList.add('help-left-item-active');
            this.parentNode.parentNode.parentNode.children[1].children[i].classList.remove(
                'mit-hide'
            );
        },
        false
    );
}

let jumpLayer = function() {
    let html = document.querySelector('.home-layer-content').innerHTML;
    Layer.fn('home-layer', html, 'home-layer-box');
};

document.querySelectorAll('.jump-layer').forEach(item => {
    item.addEventListener('click', jumpLayer, false);
});

window.download = function() {
    location.href = window.url;
};
